package com.taylor.spring5.dao;

import com.taylor.spring5.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author taylor
 * @Description: TODO
 * @date 2021/4/5 22:31
 */
@Repository
public class BookDaoImpl implements BookDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public int add(Book book) {
        //1 创建 sql 语句
        String sql =  "insert into t_book(book_id, book_name, author) values(?,?,?)";
        //2 调用方法实现
        Object[] args = {book.getBookId(), book.getBookName(),book.getAuthor()};
        jdbcTemplate.update(sql, args);
        return 1;
    }
}
